/**
 * 圈子动态数据解析
 */
package cn.suse.android.logic;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import cn.suse.android.entity.Circle;
import cn.suse.android.entity.Page;
import cn.suse.android.entity.Circle;
import cn.suse.android.entity.User;


/**
 * @author liubin
 * Create DateTime:Oct 16, 2012 10:53:17 AM
 * Description:
 * @Version: 1.0.0
 */
public class CircleParse extends BaseParse<Circle> {

	/* (non-Javadoc)
	 * @see cn.suse.android.logic.BaseParse#parseData(java.lang.String)
	 */
	@Override
	public List<Circle> parseData(String content) {
		List<Circle> lists = null;
		try {
			JSONObject json = new JSONObject(content);
			lists = new ArrayList<Circle>();
			Page page = parsePage(json.getJSONObject("paging"));
			JSONArray jsonArray = json.getJSONArray("data");
				for (int j = 0; j <jsonArray .length(); j++) {
					JSONObject jsonObject = jsonArray.getJSONObject(j);
					Circle circle = new Circle();
					circle.setPaging(page);
					circle.setcTime(jsonObject.getString("ctime"));
					circle.setSid(jsonObject.getString("stid"));
					circle.setTid(jsonObject.getString("tid"));
					User user = new User();
					JSONObject userObject = jsonObject.getJSONObject("user");
					user.setUid(userObject.getString("uid"));
					user.setName(userObject.getString("name"));
					user.setGender(userObject.getString("gender"));
					user.setLogo50(userObject.getString("logo50"));
					circle.setUser(user);
					try {
						JSONObject mainObject = jsonObject.getJSONArray("main").getJSONObject(0);
						circle.setTxt(mainObject.getString("txt"));
						circle.setTitle(mainObject.getString("title"));
						circle.setImg_url(mainObject.getString("img_url"));
						circle.setSwf_url(mainObject.getString("swf_url"));
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					lists.add(circle);
				}
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		
		return lists;
	}

}
